/*
 * GenetischerAlgorithmusView.java
 */
package genetischeralgorithmus;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import java.awt.Graphics;
import java.util.*;
import java.awt.*;

/**
 * The application's main frame.
 */
public class GenetischerAlgorithmusView extends FrameView {

    int n = 1;
    Algorithmus algo1 = new Algorithmus(this);

    public GenetischerAlgorithmusView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);


        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }

                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);

                } else if ("message".equals(propertyName)) {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer) (evt.getNewValue());

                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = GenetischerAlgorithmusApp.getApplication().getMainFrame();
            aboutBox = new GenetischerAlgorithmusAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        GenetischerAlgorithmusApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        canvas1 = new java.awt.Canvas();
        jLabel1 = new javax.swing.JLabel();
        StartButton = new javax.swing.JButton();
        Coding = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        Selection = new javax.swing.JComboBox();
        Recombination = new javax.swing.JComboBox();
        Mutation = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        blalabel = new javax.swing.JLabel();
        blubblable = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        MaxPopSize = new javax.swing.JTextField();
        MaxGen = new javax.swing.JTextField();
        MaxAge = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        PopGrowth = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        MutDegree = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        StartPopulation = new javax.swing.JLabel();
        StartPop = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        survivors = new javax.swing.JTextField();
        ClearButton = new javax.swing.JButton();
        destinationlist = new java.awt.TextArea();
        currGen = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        currPopSize = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        currBest = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        examples = new javax.swing.JMenu();
        examplePlaces10 = new javax.swing.JMenuItem();
        examplePlaces20 = new javax.swing.JMenuItem();
        examplePlaces30 = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();

        mainPanel.setName("mainPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(genetischeralgorithmus.GenetischerAlgorithmusApp.class).getContext().getResourceMap(GenetischerAlgorithmusView.class);
        canvas1.setBackground(resourceMap.getColor("canvas1.background")); // NOI18N
        canvas1.setName("canvas1"); // NOI18N
        canvas1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                canvas1MouseClicked(evt);
            }
        });

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        StartButton.setText(resourceMap.getString("StartButton.text")); // NOI18N
        StartButton.setName("StartButton"); // NOI18N
        StartButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                StartButtonMouseClicked(evt);
            }
        });

        Coding.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Path", "Binary", "Matrix" }));
        Coding.setName("Coding"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        Selection.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Rholette Wheel", "Tournament" }));
        Selection.setName("Selection"); // NOI18N

        Recombination.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "PMX", "OX", "AP", "CX" }));
        Recombination.setName("Recombination"); // NOI18N

        Mutation.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "none", "DM", "EM", "ISM", "SIM", "IVM", "SM" }));
        Mutation.setName("Mutation"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        blalabel.setText(resourceMap.getString("blalabel.text")); // NOI18N
        blalabel.setName("blalabel"); // NOI18N

        blubblable.setText(resourceMap.getString("blubblable.text")); // NOI18N
        blubblable.setName("blubblable"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        MaxPopSize.setText(resourceMap.getString("MaxPopSize.text")); // NOI18N
        MaxPopSize.setName("MaxPopSize"); // NOI18N

        MaxGen.setText(resourceMap.getString("MaxGen.text")); // NOI18N
        MaxGen.setName("MaxGen"); // NOI18N

        MaxAge.setText(resourceMap.getString("MaxAge.text")); // NOI18N
        MaxAge.setName("MaxAge"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        PopGrowth.setText(resourceMap.getString("PopGrowth.text")); // NOI18N
        PopGrowth.setName("PopGrowth"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        MutDegree.setText(resourceMap.getString("MutDegree.text")); // NOI18N
        MutDegree.setName("MutDegree"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        StartPopulation.setText(resourceMap.getString("StartPopulation.text")); // NOI18N
        StartPopulation.setName("StartPopulation"); // NOI18N

        StartPop.setText(resourceMap.getString("StartPop.text")); // NOI18N
        StartPop.setName("StartPop"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        survivors.setText(resourceMap.getString("survivors.text")); // NOI18N
        survivors.setName("survivors"); // NOI18N

        ClearButton.setFont(resourceMap.getFont("ClearButton.font")); // NOI18N
        ClearButton.setText(resourceMap.getString("ClearButton.text")); // NOI18N
        ClearButton.setName("ClearButton"); // NOI18N
        ClearButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ClearButtonMouseClicked(evt);
            }
        });

        destinationlist.setName("destinationlist"); // NOI18N

        currGen.setText(resourceMap.getString("currGen.text")); // NOI18N
        currGen.setName("currGen"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        currPopSize.setText(resourceMap.getString("currPopSize.text")); // NOI18N
        currPopSize.setName("currPopSize"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        currBest.setText(resourceMap.getString("currBest.text")); // NOI18N
        currBest.setName("currBest"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(canvas1, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel7)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(StartButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(ClearButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(57, 57, 57)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                                    .addComponent(jLabel6)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
                                .addGroup(mainPanelLayout.createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addGap(8, 8, 8)))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addComponent(jLabel13)
                                .addGap(8, 8, 8)))
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(currBest, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(currPopSize, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
                            .addComponent(currGen, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(73, 73, 73)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(mainPanelLayout.createSequentialGroup()
                                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel10)
                                        .addComponent(jLabel9)
                                        .addComponent(jLabel11)
                                        .addComponent(jLabel12))
                                    .addGap(7, 7, 7))
                                .addGroup(mainPanelLayout.createSequentialGroup()
                                    .addComponent(jLabel8)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                .addGroup(mainPanelLayout.createSequentialGroup()
                                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(StartPopulation)
                                        .addComponent(jLabel5))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(StartPop)
                                .addComponent(MaxPopSize)
                                .addComponent(MaxGen)
                                .addComponent(MaxAge, javax.swing.GroupLayout.DEFAULT_SIZE, 52, Short.MAX_VALUE)
                                .addComponent(PopGrowth)
                                .addComponent(MutDegree)
                                .addComponent(survivors)))
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(blalabel)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(blubblable))
                        .addGap(18, 18, 18)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(Selection, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(Recombination, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(Coding, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(Mutation, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(61, Short.MAX_VALUE))
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(destinationlist, javax.swing.GroupLayout.DEFAULT_SIZE, 698, Short.MAX_VALUE))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(Coding, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(Selection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(Recombination, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(blalabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(Mutation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(blubblable))
                        .addGap(48, 48, 48)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(MaxPopSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(MaxGen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(MaxAge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(PopGrowth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(MutDegree, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12)))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(canvas1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(StartPop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(StartPopulation)
                            .addComponent(jLabel7))
                        .addGap(18, 18, 18)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(survivors, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addComponent(StartButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(ClearButton))))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(currGen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(currPopSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(currBest, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13))))
                .addComponent(destinationlist, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(genetischeralgorithmus.GenetischerAlgorithmusApp.class).getContext().getActionMap(GenetischerAlgorithmusView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        examples.setAction(actionMap.get("example30")); // NOI18N
        examples.setText(resourceMap.getString("examples.text")); // NOI18N
        examples.setName("examples"); // NOI18N

        examplePlaces10.setAction(actionMap.get("lol")); // NOI18N
        examplePlaces10.setText(resourceMap.getString("examplePlaces10.text")); // NOI18N
        examplePlaces10.setName("examplePlaces10"); // NOI18N
        examplePlaces10.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                examplePlaces10MouseClicked(evt);
            }
        });
        examples.add(examplePlaces10);

        examplePlaces20.setText(resourceMap.getString("examplePlaces20.text")); // NOI18N
        examplePlaces20.setName("examplePlaces20"); // NOI18N
        examples.add(examplePlaces20);

        examplePlaces30.setAction(actionMap.get("example30")); // NOI18N
        examplePlaces30.setText(resourceMap.getString("examplePlaces30.text")); // NOI18N
        examplePlaces30.setName("examplePlaces30"); // NOI18N
        examples.add(examplePlaces30);

        menuBar.add(examples);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 719, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 699, Short.MAX_VALUE)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void canvas1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_canvas1MouseClicked
        
        destinationlist.setText(destinationlist.getText() + "\n" + "Ort" + n++ + ": " + Double.toString(canvas1.getMousePosition().getX()) + "  " + Double.toString(canvas1.getMousePosition().getY()));
        Point p1 = new Point((int) (canvas1.getMousePosition().getX()), (int) (canvas1.getMousePosition().getY()));
        paint(canvas1.getGraphics(), (int) (p1.getX()), (int) (p1.getY()));
        algo1.addPoint(p1);

    }//GEN-LAST:event_canvas1MouseClicked

    private void StartButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_StartButtonMouseClicked
        algo1.startTravelingSalesman();
    }//GEN-LAST:event_StartButtonMouseClicked

    private void ClearButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ClearButtonMouseClicked
        algo1.clear();
        n = 1;
    }//GEN-LAST:event_ClearButtonMouseClicked

    public void printExamplePlaces10() {
        Point p1 = new Point(75, 73);
        Point p2 = new Point(158, 75);
        Point p3 = new Point(113, 125);
        Point p4 = new Point(46, 187);
        Point p5 = new Point(78, 202);
        Point p6 = new Point(114, 210);
        Point p7 = new Point(156, 203);
        Point p8 = new Point(190, 181);
        Point p9 = new Point(174, 78);
        Point p10 = new Point(64, 81);

        algo1.addPoint(p1);
        algo1.addPoint(p2);
        algo1.addPoint(p3);
        algo1.addPoint(p4);
        algo1.addPoint(p5);
        algo1.addPoint(p6);
        algo1.addPoint(p7);
        algo1.addPoint(p8);
        algo1.addPoint(p9);
        algo1.addPoint(p10);

        paint(canvas1.getGraphics(), (int) (p1.getX()), (int) (p1.getY()));
        paint(canvas1.getGraphics(), (int) (p2.getX()), (int) (p2.getY()));
        paint(canvas1.getGraphics(), (int) (p3.getX()), (int) (p3.getY()));
        paint(canvas1.getGraphics(), (int) (p4.getX()), (int) (p4.getY()));
        paint(canvas1.getGraphics(), (int) (p5.getX()), (int) (p5.getY()));
        paint(canvas1.getGraphics(), (int) (p6.getX()), (int) (p6.getY()));
        paint(canvas1.getGraphics(), (int) (p7.getX()), (int) (p7.getY()));
        paint(canvas1.getGraphics(), (int) (p8.getX()), (int) (p8.getY()));
        paint(canvas1.getGraphics(), (int) (p9.getX()), (int) (p9.getY()));
        paint(canvas1.getGraphics(), (int) (p10.getX()), (int) (p10.getY()));

    }

    public void printExample30(){

Point p1 = new Point(17, 66);
Point p2 = new Point(45, 44);
Point p3 = new Point(81, 35);
Point p4 = new Point(123, 33);
Point p5 = new Point(170, 41);
Point p6 = new Point(210, 67);
Point p7 = new Point(231, 102);
Point p8 = new Point(238, 135);
Point p9 = new Point(239, 174);
Point p10 = new Point(236, 205);
Point p11 = new Point(222, 239);
Point p12 = new Point(195, 257);
Point p13 = new Point(153, 264);
Point p14 = new Point(107, 260);
Point p15 = new Point(67, 252);
Point p16 = new Point(41, 234);
Point p17 = new Point(24, 204);
Point p18 = new Point(14, 178);
Point p19 = new Point(10, 148);
Point p20 = new Point(14, 127);
Point p21 = new Point(16, 94);
Point p22 = new Point(193, 52);
Point p23 = new Point(222, 86);
Point p24 = new Point(240, 159);
Point p25= new Point(88, 258);
Point p26 = new Point(150, 43);
Point p27 = new Point(131, 260);
Point p28 = new Point(179, 265);
Point p29 = new Point(232, 223);
Point p30 = new Point(103, 37);

algo1.addPoint(p1);
algo1.addPoint(p2);
algo1.addPoint(p3);
algo1.addPoint(p4);
algo1.addPoint(p5);
algo1.addPoint(p6);
algo1.addPoint(p7);
algo1.addPoint(p8);
algo1.addPoint(p9);
algo1.addPoint(p10);
algo1.addPoint(p11);
algo1.addPoint(p12);
algo1.addPoint(p13);
algo1.addPoint(p14);
algo1.addPoint(p15);
algo1.addPoint(p16);
algo1.addPoint(p17);
algo1.addPoint(p18);
algo1.addPoint(p19);
algo1.addPoint(p20);
algo1.addPoint(p21);
algo1.addPoint(p22);
algo1.addPoint(p23);
algo1.addPoint(p24);
algo1.addPoint(p25);
algo1.addPoint(p26);
algo1.addPoint(p27);
algo1.addPoint(p28);
algo1.addPoint(p29);
algo1.addPoint(p30);

 paint(canvas1.getGraphics(), (int) (p1.getX()), (int) (p1.getY()));
 paint(canvas1.getGraphics(), (int) (p2.getX()), (int) (p2.getY()));
 paint(canvas1.getGraphics(), (int) (p3.getX()), (int) (p3.getY()));
 paint(canvas1.getGraphics(), (int) (p4.getX()), (int) (p4.getY()));
 paint(canvas1.getGraphics(), (int) (p5.getX()), (int) (p5.getY()));
 paint(canvas1.getGraphics(), (int) (p6.getX()), (int) (p6.getY()));
 paint(canvas1.getGraphics(), (int) (p7.getX()), (int) (p7.getY()));
 paint(canvas1.getGraphics(), (int) (p8.getX()), (int) (p8.getY()));
 paint(canvas1.getGraphics(), (int) (p9.getX()), (int) (p9.getY()));
 paint(canvas1.getGraphics(), (int) (p10.getX()), (int) (p10.getY()));
 paint(canvas1.getGraphics(), (int) (p11.getX()), (int) (p11.getY()));
 paint(canvas1.getGraphics(), (int) (p12.getX()), (int) (p12.getY()));
 paint(canvas1.getGraphics(), (int) (p13.getX()), (int) (p13.getY()));
 paint(canvas1.getGraphics(), (int) (p14.getX()), (int) (p14.getY()));
 paint(canvas1.getGraphics(), (int) (p15.getX()), (int) (p15.getY()));
 paint(canvas1.getGraphics(), (int) (p16.getX()), (int) (p16.getY()));
 paint(canvas1.getGraphics(), (int) (p17.getX()), (int) (p17.getY()));
 paint(canvas1.getGraphics(), (int) (p18.getX()), (int) (p18.getY()));
 paint(canvas1.getGraphics(), (int) (p19.getX()), (int) (p19.getY()));
 paint(canvas1.getGraphics(), (int) (p20.getX()), (int) (p20.getY()));
 paint(canvas1.getGraphics(), (int) (p21.getX()), (int) (p21.getY()));
 paint(canvas1.getGraphics(), (int) (p22.getX()), (int) (p22.getY()));
 paint(canvas1.getGraphics(), (int) (p23.getX()), (int) (p23.getY()));
 paint(canvas1.getGraphics(), (int) (p24.getX()), (int) (p24.getY()));
 paint(canvas1.getGraphics(), (int) (p25.getX()), (int) (p25.getY()));
 paint(canvas1.getGraphics(), (int) (p26.getX()), (int) (p26.getY()));
 paint(canvas1.getGraphics(), (int) (p27.getX()), (int) (p27.getY()));
 paint(canvas1.getGraphics(), (int) (p28.getX()), (int) (p28.getY()));
 paint(canvas1.getGraphics(), (int) (p29.getX()), (int) (p29.getY()));
 paint(canvas1.getGraphics(), (int) (p30.getX()), (int) (p30.getY()));
    }

    private void examplePlaces10MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_examplePlaces10MouseClicked
    }//GEN-LAST:event_examplePlaces10MouseClicked

    public void paint(Graphics g, int x, int y) {
        g.setColor(Color.red);
        g.drawOval(x, y, 4, 4);
    }

    @Action
    public void lol() {
        printExamplePlaces10();
    }

    @Action
    public void example30() {
        printExample30();

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ClearButton;
    public javax.swing.JComboBox Coding;
    public javax.swing.JTextField MaxAge;
    public javax.swing.JTextField MaxGen;
    public javax.swing.JTextField MaxPopSize;
    public javax.swing.JTextField MutDegree;
    public javax.swing.JComboBox Mutation;
    public javax.swing.JTextField PopGrowth;
    public javax.swing.JComboBox Recombination;
    public javax.swing.JComboBox Selection;
    private javax.swing.JButton StartButton;
    public javax.swing.JTextField StartPop;
    private javax.swing.JLabel StartPopulation;
    private javax.swing.JLabel blalabel;
    private javax.swing.JLabel blubblable;
    public java.awt.Canvas canvas1;
    public javax.swing.JTextField currBest;
    public javax.swing.JTextField currGen;
    protected javax.swing.JTextField currPopSize;
    public java.awt.TextArea destinationlist;
    private javax.swing.JMenuItem examplePlaces10;
    private javax.swing.JMenuItem examplePlaces20;
    public javax.swing.JMenuItem examplePlaces30;
    private javax.swing.JMenu examples;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    public javax.swing.JTextField survivors;
    // End of variables declaration//GEN-END:variables
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;
    /**
     * paint method in your own class that extends Canvas
     *
     * @param g where to paint e.g. printer, screen, RAM
     */
}



